import request from '@/utils/request';
import type { BaseBeanModel, ResponsePageData, ResponseBaseData, QueryParamModel } from '@/api/model/baseModel';
import type { downloadParam } from '@/utils/download-util';
import { downloadSysFile, download } from '@/utils/download-util';

const basePath = '/appsys/sysdownloadfiles';
/** 导出记录表 */
export interface SysDownloadFilesDto extends BaseBeanModel {
  /** 方法名 */
  medthonName?: string;
  /** 文件路径 */
  fileUrl?: string;
  /** 文件类型 */
  fileType?: string;
  /** 模块名 */
  moduleName?: string;
  /** 文件名 */
  fileName?: string;
  /** 下载状态 */
  status?: string;
  /** 备注 */
  remark?: string;
  /** 保存类型 */
  saveType?: string;
  /** 总记录数 */
  allCount?: number;
  /** 已处理记录数 */
  successCount?: number;
}

/** 获取分页数据 */
export function listSysDownloadFilesByPage(param: QueryParamModel): Promise<ResponsePageData<SysDownloadFilesDto>> {
  return request.post(`${basePath}/search-by-page/v1`, param);
}

/** 根据id加载数据 */
export function getSysDownloadFiles(id: string): Promise<ResponseBaseData<SysDownloadFilesDto>> {
  return request.get(`${basePath}/get/${id}/v1`);
}

/** 保存表单数据 */
export function saveSysDownloadFiles(form: SysDownloadFilesDto): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/save/v1`, form);
}

/** 根据id集合删除数据 */
export function delSysDownloadFiles(ids: [string]): Promise<ResponseBaseData<any>> {
  return request.delete(`${basePath}/delete-by-ids/v1`, { data: ids });
}

/** 导出Excel */
export function exportExcel(param: any) {
  const download = {
    url: `${basePath}/exportData/v1`,
    data: param,
    method: 'post'
  } as downloadParam;
  return downloadSysFile(download);
}
/** 下载导出文件
 *  @param fileId 文件ID
 */
export function downloadFiles(fileId) {
  const downloadDto = {
    url: `${basePath}/download/v1/${fileId}`,
    data: fileId,
    method: 'get'
  } as downloadParam;
  return download(downloadDto);
}
